<?php
require_once __DIR__ . '/../vendor/autoload.php';

use WenwenPay\Config\Config;
use WenwenPay\PaymentService;
use WenwenPay\Exception\PaymentException;

try {
    // 初始化配置
    $config = new Config(
        '091662d1b3ac4e9dba9398810f1ba15f',  // 替换为您的商户号
        'fafdf8944ca641b29b35245f6e79f011' // 替换为您的密钥
    );
    // $config = new Config(
    //     'test_agent_no',  // 替换为您的商户号
    //     'test_secret_key' // 替换为您的密钥
    // );
    $payment = new PaymentService($config);

    // // 测试余额查询
    // echo "开始查询余额...\n";
    // $amountResult = $payment->amount();
    // echo json_encode($amountResult, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";

    // 测试代付请求
    echo "开始测试代付...\n";
    $transferResult = $payment->transfer([
        'id_card_no' => '330327********095X',
        'bank_card_no' => '621483******7232',
        'phone' => '158****0922',
        'name' => '张三',
        'amount' => '1.00',
        'client_tx_order_no' => date('YmdHis') . rand(1000, 9999),
        "client_customize_element"=>"A", //客户端自定义字段
    ]);
    // echo json_encode($transferResult, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";

    // // 测试订单查询
    // if ($transferResult['success']) {
    //     echo "开始查询订单...\n";
    //     $queryResult = $payment->query($transferResult['responseData']['payrollId']);
    //     echo json_encode($queryResult, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
    // }

    // 测试列表查询
    echo "开始查询列表...\n";
    $listResult = $payment->list([
        'page_number' => '1',
        'page_limit' => '10',
        'start_date' => date('Y-m-d'),
        'end_date' => date('Y-m-d'),
        'payrollId' => '170592'
    ]);
    echo json_encode($listResult, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";

} catch (PaymentException $e) {
    echo "错误: " . $e->getMessage() . "\n";
    echo "详细信息: " . json_encode($e->getData(), JSON_PRETTY_PRINT) . "\n";
    exit(1);
} catch (\Exception $e) {
    echo "系统错误: " . $e->getMessage() . "\n";
    exit(1);
} 